package com.itcc.service.impl;

import com.itcc.dao.AddressDao;
import com.itcc.dao.impl.AddressDaoImpl;
import com.itcc.entity.Address;
import com.itcc.service.AddressService;

import java.sql.SQLException;
import java.util.List;


public class AddressServiceImpl implements AddressService {

    @Override
    public List<Address> findAddressByUid(int uid) throws SQLException {

        AddressDao addressDao=new AddressDaoImpl();
        List<Address> list=addressDao.selectAddressByUid(uid);
        return list;
    }

    @Override
    public void saveAddress(Address address) throws SQLException {

        AddressDao addressDao=new AddressDaoImpl();
        addressDao.insertAddress(address);
    }

    @Override
    public void deleteAddressByAid(String aid) throws SQLException {

        AddressDao addressDao=new AddressDaoImpl();
        addressDao.deleteAddressByAid(aid);
    }

    @Override
    public void setAddressToDefault(String aid, int uid) throws SQLException {
         AddressDao addressDao=new AddressDaoImpl();

         addressDao.updateAddressToDefault(aid);
         addressDao.updateAddressToCommons(aid,uid);
    }

    @Override
    public void updateByAid(Address address) throws SQLException {

        AddressDao addressDao=new AddressDaoImpl();

        addressDao.updateAddressByAid(address);
    }
}
